/*******************************************************************************
 * Copyright 2011-2012 Dik Grapendaal
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package sh.grapendaal.tsuushin.service;

import sh.grapendaal.tsuushin.message.IncomingMessage;
import sh.grapendaal.tsuushin.tracking.Context;

public interface ModuleService extends Service {
	/**
	 * The Spring configuration to be used when loading modules.
	 */
	static final String SPRING_MODULE_CONFIGURATION_FILE = "spring-module.xml";

	/**
	 * Dispatches the given message in the given context to applicable callbacks
	 * in the running modules.
	 * 
	 * @param context
	 *            The context of the message.
	 * @param message
	 *            The message.
	 */
	void dispatchCallbacks(Context context, IncomingMessage message);

	/**
	 * Starts the ModuleService. After starting, it will monitor the modules
	 * directory for changes and load and unload modules as needed.
	 * 
	 * @throws Exception
	 *             If the ModuleService could not be started.
	 */
	void start() throws Exception;

	/**
	 * Cleanly stops any processes the ModuleService has going on.
	 */
	void stop();

	/**
	 * Refreshes the modules directory to see if any modules need to be
	 * loaded/unloaded or even reloaded.
	 */
	void refreshModules();
}
